package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DatabaseOperations;
import models.StudentBean;

/**
 * Servlet implementation class RegistrationServlet
 */
@WebServlet("/Registration")
public class Registration extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Registration() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try{
		String name=(request.getParameter("name"));
		String email=(request.getParameter("email"));
		String password=(request.getParameter("password"));
		String password2=(request.getParameter("password2"));
		int age=Integer.parseInt(request.getParameter("age"));
		int gender=Integer.parseInt(request.getParameter("gender"));
		String region=(request.getParameter("region"));
		String about=(request.getParameter("about"));
	   
		
		System.out.println("In the Registration Servlet");
		StudentBean student= new StudentBean();
		
		student.setName(name);
		student.setEmail(email);
		student.setPassword(password);
		student.setIsMale(gender);
		student.setAge(age);
		student.setAbout(about);
		student.setRegion(region);
		boolean isInserted=DatabaseOperations.Register(student);
		
		if(isInserted){
			System.out.println("Succesfully Inserted !");
			
		
		}
		else{
			System.out.println("Something Wrongggg !");
		}
		
			
		}
		catch (Throwable exc)
        {
            System.out.println(exc);
        }
		
		
	}

}
